//
//  UserHeaderCell.m
//  QQplayground
//
//  Created by zhangxy on 2018/5/22.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "UserHeaderCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@implementation UserHeaderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _imgHeader.layer.cornerRadius = _imgHeader.height/2;
    _imgHeader.layer.masksToBounds = YES;

    [_labNam attributeFont:FontSeventeen textColor:UIColorFromRGB(TextWhiteColor)];
    [_labMessage attributeFont:FontThirteen textColor:UIColorFromRGB(TextWhiteColor)];
    self.contentView.backgroundColor =  UIColorFromRGB(BgTitleColor);
}


-(void)dataToView:(User *) user{
    if(user){
        [_imgHeader sd_setImageWithURL:[NSURL URLWithString:user.user_avatar] placeholderImage:[UIImage imageNamed:@"icon_app"]];
        [_labNam setText:user.user_name];
//        [_btnLevel setTitle:[NSString stringWithFormat:@"Lv %zd",user.group_now_grade] forState:0];
        if([UserUtil getUser].isOnline){
            _labMessage.text = @"点击进入主页";
            _imgSex.hidden = NO;
//            _btnLevel.hidden = NO;
        }else{
            _imgSex.hidden = YES;
//            _btnLevel.hidden = YES;
            _labNam.text = @"点击登录账号";
            _labMessage.text = @"获取积分，收藏你喜欢的内容";
        }
        
//        CGRect f = _labNam.frame;
//        CGSize s = [self autoWidthOfLabel:_labNam with:f.size.height];
//        
//        CGRect sf = _imgSex.frame;
//        sf.origin.x = f.origin.x+s.width + 10;
//        [_imgSex setFrame:sf];
        
//        CGRect lf = _btnLevel.frame;
//        lf.origin.x = sf.origin.x + sf.size.width + 10;
//        lf.origin.y = f.origin.y;
//        _btnLevel.frame = lf;
    }
}


/**
 计算Label高度
 
 @param label 要计算的label，设置了值
 @param width label的最大宽度
 */
- (CGSize )autoWidthOfLabel:(UILabel *)label with:(CGFloat )height{
    //Calculate the expected size based on the font and linebreak mode of your label
    // FLT_MAX here simply means no constraint in height
    CGSize maximumLabelSize = CGSizeMake(FLT_MAX, height);
    
    CGSize expectedLabelSize = [label sizeThatFits:maximumLabelSize];
    
    //adjust the label the the new height.
    CGRect newFrame = label.frame;
    newFrame.size.width = expectedLabelSize.width;
    label.frame = newFrame;
    [label updateConstraintsIfNeeded];
    
    return expectedLabelSize;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
